/*
 * Java CMPP API
 * Copyright (C) 1998 - 2002 by Xu Youming
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html
 * Java CMPP API author: xuym@bc-info.net
 * Java CMPP API Homepage: http://cmppapi.sourceforge.net/
 * $Id: SequenceNumberScheme.java,v 1.1 2008/03/19 02:56:56 xym Exp $
 */
package com.bci.cmpp.util;

/**
 * CMPP packet sequence numbering scheme interface. Implementations of this
 * interface provide a {@link com.bci.cmpp.Connection}with a unique number for
 * each call to <code>nextNumber</code>. This number is used as the packet's
 * sequence number in the CMPP header. The default implementation (
 * {@link DefaultSequenceScheme}) counts monotonically from 1 upwards for each
 * number requested. While this is the CMPP specification's recommended
 * behaviour, there is no requirement for 2 sequentially-requested numbers to be
 * numerically sequential.
 * 
 * @author Xu Youming
 * @version 1.0
 */
public interface SequenceNumberScheme {

    public static final int PEEK_UNSUPPORTED = -1;

    /**
     * Get the next number in this sequence's scheme. An implementation of this
     * interface <b>must </b> guard against multi-threaded access to this method
     * to prevent more than one thread getting the same sequence number.
     */
    public int nextNumber();
    
    /**
     * Get the next number and then peek nth number in this sequence's scheme. 
     * An implementation of this interface <b>must </b> guard against 
     * multi-threaded access to this method to prevent more than one thread 
     * getting the same sequence number.
     */
    public int getAndAdd(int nth);

    /**
     * Get the next number in this sequence's scheme without causing it to move
     * to the next-in-sequence. This method returns the number that will be
     * returned by the next call to <code>nextNumber</code> without actually
     * increasing the sequence. Multiple calls to <code>peek</code> will
     * return the same number until a call to <code>nextNumber</code> is made.
     */
    public int peek();

    /**
     * Get the nth next number in this sequence's scheme without causing it to
     * move to the next-in-sequence. This method returns the <code>nth</code>
     * next number in the sequence. This is an optional operation. If a sequence
     * numbering scheme does not support this operation, it should always return
     * {@link #PEEK_UNSUPPORTED}to the caller.
     */
    public int peek(int nth);

    /**
     * Reset the sequence scheme to the beginning of the sequence.
     */
    public void reset();
}